import { Filter,GlProgram} from "pixi.js";
import vertex from '@/filters/defaultFilter.vert?raw';
import fragment from '@/filters/FlashTone/FlashTone.frag?raw';

export class FlashToneFilter extends Filter{
    constructor(){
        super({
            glProgram:new GlProgram({
                vertex,
                fragment
            }),
            resources:{
                localUniforms:{
                    flashTone:{
                        value:[0.0,0.0,0.0,0.0],
                        type:'vec4<f32>',
                        size:1
                    },
                    fadeAlpha:{
                        value:1.0,
                        type:'f32',
                        size:1
                    },
                    tone:{
                        value:[0.0,0.0,0.0,0.0],
                        type:'vec4<f32>',
                        size:1
                    }
                }
            }
        });
    }

    setFlashTone(r,g,b,a){
        let flashTone=this.resources.localUniforms.uniforms.flashTone;
        flashTone[0]=r/255;
        flashTone[1]=g/255;
        flashTone[2]=b/255;
        flashTone[3]=a/255;
    }

    setFadeAlpha(a){
        this.resources.localUniforms.uniforms.fadeAlpha=a/255;
    }

    setTone(r,g,b,a){
        let tone=this.resources.localUniforms.uniforms.tone;
        tone[0]=r/255;
        tone[1]=g/255;
        tone[2]=b/255;
        tone[3]=a/255;
    }
}